package com.lxm.shownews.channel.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lxm.shownews.R;
import com.lxm.shownews.bean.News;
import com.lxm.shownews.channel.OnRecyclerViewListener;
import com.lxm.shownews.utils.DateUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lxm on 2016/2/24.
 */
public class NewsRecyclerAdapter extends NewsBaseAdapter implements View.OnClickListener {

    public NewsRecyclerAdapter(List<News> newsList) {
        super(newsList);
    }


    @Override
    public NoneImgVH onCreateNoneImgVH(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_noneimg, parent, false);
        NoneImgVH noneImgVH = new NoneImgVH(view);
        view.setOnClickListener(this);
        noneImgVH.click.setOnClickListener(this);
        return noneImgVH;
    }

    @Override
    public void onBindNoneImgVH(BaseVH baseVH, int position) {
        News news = newsList.get(position);
        NoneImgVH noneImgVH = (NoneImgVH) baseVH;
        noneImgVH.title.setText(news.getTitle()+"NoneImg");
        noneImgVH.pubDate.setText(DateUtils.timeLogicShow(news.getPubDate()));
        noneImgVH.source.setText(news.getSource());
        noneImgVH.itemView.setTag(news);
    }

    @Override
    public OneImgVH onCreateOneImgVH(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_oneimg, parent, false);
        view.setOnClickListener(this);
        OneImgVH oneImgVH = new OneImgVH(view);
        oneImgVH.click.setOnClickListener(this);
        return oneImgVH;
    }

    @Override
    public void onBindOneImgVH(BaseVH baseVH, int position) {
        News news = newsList.get(position);
        OneImgVH oneImgVH = (OneImgVH) baseVH;
        oneImgVH.title.setText(news.getTitle() + "OneImg");
        oneImgVH.pubDate.setText(DateUtils.timeLogicShow(news.getPubDate()));
        oneImgVH.source.setText(news.getSource());
        oneImgVH.itemView.setTag(news);
        Picasso.with(this.context).load(news.getImageurls().get(0).getUrl())
                .into(oneImgVH.img);

    }

    @Override
    public DoubleImgVH onCreateDoubleImgVH(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_oneimg, parent, false);
        DoubleImgVH doubleImgVH = new DoubleImgVH(view);
        view.setOnClickListener(this);
        doubleImgVH.click.setOnClickListener(this);
        return doubleImgVH;
    }

    @Override
    public void onBindDoubleImgVH(BaseVH baseVH, int position) {
        News news = newsList.get(position);
        DoubleImgVH doubleImgVH = (DoubleImgVH) baseVH;
        doubleImgVH.title.setText(news.getTitle() + "DoubleImg");
        doubleImgVH.pubDate.setText(DateUtils.timeLogicShow(news.getPubDate()));
        doubleImgVH.source.setText(news.getSource());
        doubleImgVH.itemView.setTag(news);
        Picasso.with(this.context).load(news.getImageurls().get(0).getUrl() + "")
                .into(doubleImgVH.img);
    }

    @Override
    public TreeImgVH onCreateTreeImgVH(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_doubleimg, parent, false);
        TreeImgVH oneImgVH = new TreeImgVH(view);
        view.setOnClickListener(this);
        oneImgVH.click.setOnClickListener(this);
        return oneImgVH;
    }

    @Override
    public void onBindTreeImgVH(BaseVH baseVH, int position) {
        News news = newsList.get(position);
        TreeImgVH oneImgVH = (TreeImgVH) baseVH;
        oneImgVH.title.setText(news.getTitle()+"TreeVH"+ "num:" + news.getImageurls().size());
        oneImgVH.pubDate.setText(DateUtils.timeLogicShow(news.getPubDate()));
        oneImgVH.source.setText(news.getSource());
        oneImgVH.itemView.setTag(news);
        oneImgVH.nineImgLayout.setImagesData(news.getImageurls());
//        Picasso.with(this.context).load(news.getImageurls().get(0) + "")
//                .into(oneImgVH.img);
    }

    @Override
    public MoreImgVH onCreateMoreImgVH(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_doubleimg, parent, false);
        MoreImgVH oneImgVH = new MoreImgVH(view);
        oneImgVH.click.setOnClickListener(this);
        view.setOnClickListener(this);
        return oneImgVH;
    }

    @Override
    public void onBindMoreImgVH(BaseVH baseVH, int position) {
        News news = newsList.get(position);
        MoreImgVH oneImgVH = (MoreImgVH) baseVH;
        oneImgVH.title.setText(news.getTitle() + "num:" + news.getImageurls().size());
        oneImgVH.pubDate.setText(DateUtils.timeLogicShow(news.getPubDate()));
        oneImgVH.source.setText(news.getSource());
        oneImgVH.itemView.setTag(news);
        oneImgVH.nineImgLayout.setImagesData(news.getImageurls());
//        Picasso.with(this.context).load(news.getImageurls().get(0) + "")
//                .into(oneImgVH.img);
    }


    @Override
    public void onClick(View v) {
        if (mRecyclerClickListener != null) {
            if (v.getId() == R.id.click) {
                mRecyclerClickListener.onEventClick(0, v.getTag());
                return;
            }
            mRecyclerClickListener.onItemClick(v, 0, v.getTag());
        }
    }
}
